package com.kaifamiao.jdbc.core;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 目标: 测试 executeUpdate "执行"DML语句的返回结果
 * Statement 接口中的 executeUpdate(String) 方法
 * 如果"执行"的SQL语句是 DML语句 则返回 行计数 (即受SQL影响的记录数目)
 * 如果"执行"的SQL语句是无需返回的语句(比如DDL语句)，则该方法返回 零
 */
public class ResultHandling2 {

    public static void main(String[] args) throws SQLException {
        DbUtil du = DbUtil.getInstance();
        du.load();
        Connection conn = du.connect();
        System.out.println( "TransactionIsolation: " + conn.getTransactionIsolation() );
        System.out.println( "Auto Commit: " + conn.getAutoCommit() );
        Statement stmt = du.create( conn );

        String delete = "DELETE FROM t_pandas WHERE id = 1122";
        int count = stmt.executeUpdate( delete );
        System.out.println( "受影响记录数: " + count );

        String insert = "INSERT INTO t_pandas (name, id) VALUES ( '大美', 1122 )";
        count = stmt.executeUpdate( insert );
        System.out.println( "受影响记录数: " + count );

        String update = "UPDATE t_pandas SET name = '小菲' WHERE id = 1122";
        count = stmt.executeUpdate( update );
        System.out.println( "受影响记录数: " + count );

        du.release( stmt );
        du.release( conn );
    }

}
